<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script>
        function *gen(x){
            yield x+2;
            return x;
        }
        /*generator函数遇到 yeild关键字函数会暂停  yield将函数切割了
        next的作用：执行这个函数，会返回一个对象 value:表示yield函数的执行结果
        */
        var g=gen(3);
        console.log(g.next())   //{value: 5, done: false} 
        console.log(g.next())  //{value: 3, done: true},true:函数执行完毕
        console.log(g.next())  //{value: undefined, done: true}
    </script>
</body>
</html>